<?php
class Admini_NavigationController extends Uuch_ManageController{
    
     public function init() {
        parent::init();
        $this->appendCss('/admins/css/yundan.css');
        $this->appendCss('/admins/css/common.css');
        $this->appendScript('/admins/js/jquery/jquery-1.7.2.min.js')->appendScript('/js/jquery.validate.min.js')->appendScript('/js/messages_cn.js')->appendScript('/js/uuch.js');
        $this->setTitle("后台导航管理");
        $this->view->type="system";
    }    
       
    public function indexAction()
    {
        $pagesize = 20;
        $pageindex = $this->getSafeParam('start');
        if (!$pageindex) {
            $pageindex = 0;
        }
        $parentId = $this->getSafeParam("parentId");
        if (!$parentId){
            $parentId = 0;
        }
        $navigationAll = Application_Model_Navigation::getNavigationFileds($parentId,$pagesize,$pageindex);
        $this->view->navigationAll = $navigationAll;
        $this->view->navigationList = $navigationAll["list"];
        $this->view->typeAll = Application_Model_Navigation::getTypeAll();
        $this->view->statusAll = Application_Model_Navigation::getStatusAll();
        $this->view->parentId = $parentId;
        $this->view->parentItem = Application_Model_Navigation::load($parentId);
    }
    
    public function addnavigationAction()
    {
        $parentId = $this->getSafeParam("parentId");
        $id = $this->getSafeParam("id");
        $name = $this->getSafeParam("name");
        $url = $this->getSafeParam("url");
        $type = $this->getSafeParam("type");
        $sign = $this->getSafeParam("sign");
        $order = $this->getSafeParam("order");
        $status = $this->getSafeParam("status");
        $isNum = $this->getSafeParam("isNum");
        $navigationId = Application_Model_Navigation::addOrEditNavigation($parentId, $id, $name, $url, $type, $sign, $order, $status, $isNum);
        if($navigationId != ""){
            $this->json(1);
        } else {
            $this->json(0);
        }
    }
    
    public function navigationdetailAction()
    {
        $id = $this->getSafeParam("id");
        $navigationItem = Application_Model_Navigation::load($id);
        if($navigationItem != null){
            $this->json(array("sj"=>1,"name"=>$navigationItem->Name,"url"=>$navigationItem->Url,"sign"=>$navigationItem->Sign,"type"=>$navigationItem->Type,"status"=>$navigationItem->Status,"order"=>$navigationItem->Order,"parentId"=>$navigationItem->parentId));
        } else {
            $this->json(array("sj"=>0));
        }
    }
    
    public function delnavigationAction()
    {
        $id = $this->getSafeParam("id");
        $navigationItem = Application_Model_Navigation::load($id);
        Application_Model_Operate::addOperate(0, null, $navigationItem->Name, "删除后台导航及下级导航", 0);
        $navigationItem->delete();
        $navigationParentItem = Application_Model_Navigation::getAllByParentId($id);
        foreach ($navigationParentItem as $npVal) {
            $npVal->delete();
        }
        if($navigationItem != null){
            $this->json(array("sj"=>1));
        } else {
            $this->json(array("sj"=>0));
        }
    }
    
    public function ordernavigationAction()
    {
        $parentId = $this->getSafeParam("parentId");
        $orderAll = $this->getSafeParam("orderAll");
        $arrOder = explode(",", $orderAll);
        $navigationParentItem = Application_Model_Navigation::getAllByParentId($parentId);
        foreach ($navigationParentItem as $key => $npVal) {
            $npVal->Order = $arrOder[$key];
            $npVal->save();
        }
        $this->json(1);
    }
}
